<?php
namespace app\admin\logic;
use app\admin\validate\ClassTi as ClassTiValidate;

class ClassTiLogic extends BaseLogic {

    /**
     * 获取题目查询条件
     * @param $ckid
     * @param $question
     * @return array
     */
    public function get_search_ct_maps($ckid,$question){
        $maps = [];
        $maps[] = ['ckid','=',$ckid];
        if(!empty($question)){
            $maps[] = ['question','like','%' . $question . '%'];
        }
        return $maps;
    }

    /**
     * 检查新增题目规则
     * @param $params
     * @return mixed
     */
    public function check_add_ct_rule($params){
        $validate = new ClassTiValidate();
        $r = $validate->scene('add')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['id','=',$params['ckid']];
        $ck_detail = model('class_ku')->get_detail($maps,'id');
        if(empty($ck_detail)){
            return $this->get_response(0,'该题库不存在');
        }

        $data['ck_detail'] = $ck_detail;
        return $this->get_response(1,'OK',$data);
    }

    /**
     * 检查修改题目规则
     * @param $params
     * @return mixed
     */
    public function check_save_ct_rule($params){
        $validate = new ClassTiValidate();
        $r = $validate->scene('edit')->check($params);
        if(!$r){
            return $this->get_response(0,$validate->getError());
        }

        $maps = [];
        $maps[] = ['id','=',$params['ctid']];
        $ct_detail = model('class_ti')->get_detail($maps,'id');
        if(empty($ct_detail)){
            return $this->get_response(0,'该题目不存在');
        }

        $data['ct_detail'] = $ct_detail;
        return $this->get_response(1,'OK',$data);
    }
}